#!/bin/bash

## Init
echo "========> STL::Build[Init]"

buildPath=$(pwd)
time=$(date "+%Y%m%d%H%M%S")
prefixPath="${buildPath}/dist${time}"
mkdir "${prefixPath}"
cd "${prefixPath}" || exit 1
prefixPath=$(pwd)
cd "${buildPath}" || exit 1
cp ./build.sh "${prefixPath}/build_back.sh"
libPath="../../../openssl.git/"
cd "${libPath}" || exit 1
libPath=$(pwd)
git branch -v | grep -F "*" | tee version.log
mv version.log "${prefixPath}/"

echo "buildPath:${buildPath}"
echo "prefixPath:${prefixPath}"
echo "libPath:${libPath}"

# exit 0
# Configure
echo "========> STL::Build[Configure]"

./config --help >& "${prefixPath}/help.log"
# exit 0

if [ -f "${libPath}/Makefile" ]; then
    make clean
fi

./config -fPIC no-shared --prefix="${prefixPath}" | tee configure.log
    
mv configure.log "${prefixPath}/"

# exit 0
# Make
echo "========> STL::Build[Make]"
make -j24 | tee make.log
mv make.log "${prefixPath}/"
# make install | tee install.log
# mv install.log "${prefixPath}/"

# exit 0
# Ended
echo "========> STL::Build[Ended]"

# Note

# 非wasm环境的配置参数
# --enable-network
# --enable-protocol=file
# --enable-demuxer=rtsp 依赖:[demuxers:asf,mov,mpegts,rm],[protocols:http,rtp,tcp,udp]



# libdyld.dylib`stack_not_16_byte_aligned_error 16位对其
# https://www.jianshu.com/p/bd652b1ac331  
# --extra-cflags="-fno-stack-check"
